package exam;

import java.util.*;

public class MainGrap {
    public static void main(String[] args) {
        int[][] weight={

                {0, 1, 12, -1, -1, -1},
                {-1, 0, 9, 3, -1, -1},
                {-1, -1, 0 ,-1 ,5 -1},
                {-1, -1, 4 ,0, 13, 15},
                {-1, -1, -1, -1, 0, 4},
                {-1, -1, -1, -1, -1 ,0}
        };
        String[] pointsStr = { "V1", "V2", "V3", "V4", "V5","V6"};
        method(weight, pointsStr);
    }
    public static void method (int[][] weight, String[] pointsStr){
        HashMap<String,Integer> map = new HashMap<>();
        for (int a=0;a<weight.length;a++){
            for (int b=0;b<weight[a].length;b++){
                if (a==0){
                    int value = weight[a][b];
                    if (weight[a][b]==-1){
                        value = 9999;
                    }
                    map.put(pointsStr[b],value);
                    System.out.println(pointsStr[b] +"  "+value);
                    continue;
                }
                if (weight[a][b]!=-1){
                    int m = map.get(pointsStr[a]) + weight[a][b];
                    if (map.get(pointsStr[b]) >m){
                        map.put(pointsStr[b] ,m);
                    }
                }
                //然后判断1 到 a点的距离和（1-b + b-a）的距离最小的
            }
        }
        for (String str:pointsStr){
            System.out.println(map.get(str));
        }
    }

    //尝试采用回溯法
    public static void getH(){

    }
}
